home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / WebFace / Source / 50-CommHardware / ppp / ppp-in.frm.z / ppp-in.frm
Encoding:
Text File  |  1997-07-30  |  12.1 KB  |  392 lines

  1. #!/usr/bin/perl5
  2. #
  3. # ppp-in.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: ppp-in.frm,v 1.35 1997/04/17 23:20:39 shotes Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23.  
  24. $conf = "/etc/passwd";
  25. $dummy = "/etc/passwd.temp";
  26. $myname = "ppp-in.cgi";
  27. $title = "Dial-in PPP Accounts";
  28.  
  29. $js_main =
  30. "which = \"none\";
  31. function runSubmit() {
  32.     // onClick gets processed before onSubmit
  33.     if(which == \"add\") return runAdd();
  34.     if(which == \"edit\") return runEdit();
  35.     if(which == \"delete\") return runDelete();
  36.     return (true);
  37. }    
  38. function markAdd() { which = \"add\"; }
  39. function markEdit() { which = \"edit\"; }
  40. function markDelete() { which = \"delete\"; }
  41. function markOther() { which = \"none\"; }
  42. function runAdd()  {
  43.     form = document.PPPForm;
  44.     if (!testLogin(form)) return (false);
  45.     return (true);
  46. }
  47. function runEdit()  {
  48.     Ctrl = document.PPPForm.chosen;
  49.     none = true;
  50.     for(i = 0; i < Ctrl.length; i++) { if (Ctrl.options[i].selected) { none = false; break; } }
  51.     if(none) { errorBox (Ctrl, \"To edit an existing account, first select an account \\nfrom the list, then click the edit button.\"); return (false); }
  52.     return (true);
  53. }
  54. function runDelete()  {
  55.     Ctrl = document.PPPForm.chosen;
  56.     none = true;
  57.     for(j = 0; j < Ctrl.length; j++) { if (Ctrl.options[j].selected) { none = false; break; } }
  58.     if(none) { errorBox (Ctrl, \"To delete an existing account, first select an account \\nfrom the list, then click the delete button.\"); return (false); }
  59.     return (true);
  60. }
  61. function testLogin(form) {
  62.     Ctrl = form.new_account;
  63.     if (Ctrl.value == \"\") { errorBox (Ctrl, \"The login name is required.\"); return (false); } 
  64.     error = testLoginChars(Ctrl.value); 
  65.     if (error == 1) { errorBox (Ctrl, \"The login name cannot be more \\nthan 8 characters long.\"); return (false); }
  66.     if (error == 2) { errorBox (Ctrl, \"The login name cannot contain the \" + illegal + \" character.\"); return (false); }
  67.     if (error == 3) { errorBox (Ctrl, \"The login name cannot contain spaces.\"); return (false); }
  68.     return (true);
  69. }
  70. function testLoginChars(word) {
  71.     if (word.length > 8) return 1;
  72.     loginChars = \"_-\.{}()*!~<>?|[]'&^\$\@\#`\\\";:\\\\/+=,%\";
  73.     for(j = 0; j < loginChars.length; j++) {
  74.         c = loginChars.charAt(j);
  75.         if (word.indexOf(c, 0) != -1) { illegal = c; return 2; }
  76.     }
  77.     for (c = 0; c < word.length; c++) { if (word.charAt(c) == ' ') return 3; }
  78.     return 0;
  79. }
  80. function errorBox (Ctrl, ErrorMessage) {
  81.     alert (ErrorMessage);  Ctrl.focus();  return;
  82. }";
  83.  
  84. $js_add =
  85. "which = \"none\";
  86. function runSubmit() {
  87.     // onClick must get processed before onSubmit
  88.     if(which == \"ok\") return runOK();
  89.     return (true);
  90. }   
  91. function markOK() { which = \"ok\"; }
  92. function markOther() { which = \"none\"; }
  93. function runOK()  {
  94.     form = document.AddForm;
  95.     // JavaScript can't look at password fields.
  96.     return (true);
  97. }
  98. function errorBox (Ctrl, ErrorMessage) {
  99.     alert (ErrorMessage);  Ctrl.focus();  return;
  100. }";
  101.  
  102. $js_edit = 
  103. "which = \"none\";
  104. function runSubmit() {
  105.     // onClick gets processed before onSubmit
  106.     if(which == \"ok\") return runOK();
  107.     return (true);
  108. }    
  109. function markOK() { which = \"ok\"; }
  110. function markOther() { which = \"none\"; }
  111. function runOK()  {
  112.     form = document.EditForm;
  113.     if (!testLogin(form)) return (false);
  114.     // JavaScript can't look at password fields.
  115.     return (true);
  116. }
  117. function testLogin(form) {
  118.     Ctrl = form.login;
  119.     if (Ctrl.value == \"\") { errorBox (Ctrl, \"The login name is required.\"); return (false); } 
  120.     error = testLoginChars(Ctrl.value); 
  121.     if (error == 1) { errorBox (Ctrl, \"The login name cannot be more \\nthan 8 characters long.\"); return (false); }
  122.     if (error == 2) { errorBox (Ctrl, \"The login name cannot contain the \" + illegal + \" character.\"); return (false); }
  123.     if (error == 3) { errorBox (Ctrl, \"The login name cannot contain spaces.\"); return (false); }
  124.     return (true);
  125. }
  126. function testLoginChars(word) {
  127.     if (word.length > 8) return 1;
  128.     loginChars = \"_-\.{}()*!~<>?|[]'&^\$\@\#`\\\";:\\\\/+=,%\";
  129.     for(j = 0; j < loginChars.length; j++) {
  130.         c = loginChars.charAt(j);
  131.         if (word.indexOf(c, 0) != -1) { illegal = c; return 2; }
  132.     }
  133.     for (c = 0; c < word.length; c++) { if (word.charAt(c) == ' ') return 3; }
  134.     return 0;
  135. }
  136. function errorBox (Ctrl, ErrorMessage) {
  137.     alert (ErrorMessage);  Ctrl.focus();  return;
  138. }";
  139.  
  140.  
  141. print "Content-type: text/html\n\n";
  142.  
  143. if ( ! -e "/usr/etc/ppp" ) {
  144.     &title_block($title);
  145.     &header_block($title);
  146.     print "<i>PPP software not installed.  Install subsystem 
  147.         </i><b>eoe.sw.ppp</b><i> from the distribution CD.</i>";
  148.     exit 0;
  149. }
  150.  
  151. &get_fields;
  152.  
  153. &getAccounts;
  154.  
  155. if (%fld) {
  156.     $fld{'chosen'} =~ /([\w.-]+)/;
  157.     $fld{'chosen'} = $1;
  158.  
  159.     $help = $document_root . $ENV{"SCRIPT_NAME"};
  160.     $help =~ s/cgi$/hlp/;
  161.     exec $help if ($fld{'help'} eq "Help");
  162.  
  163.     if ($fld{'add'}) {
  164.         &error(2,"Login name required.") if !$fld{'new_account'};
  165.         @test = getpwnam($fld{'new_account'});
  166.         &error(2,"Account already exists.") if $test[0];
  167.         &error(2,"Invalid login name.") 
  168.         if $fld{'new_account'} =~ /$METACHARS/o || $fld{'new_account'} =~ /\s/; 
  169.         $val{'login'} = $fld{'new_account'}; 
  170.         &addAccount; 
  171.     }
  172.     elsif ($fld{'delete'}) {
  173.         &error(2,"To delete an existing account, first select an account from
  174.             list, then click the delete button.") if !$fld{'chosen'};
  175.         $message = qq|Click "Ok" to save changes.|;
  176.         &generic($fld{'chosen'}); 
  177.     }
  178.     elsif ($fld{'edit'}) {
  179.         &error(2,"To edit an existing account, first select an account from
  180.             list, then click the edit button.") if !$fld{'chosen'};
  181.         $val{'login'} = $fld{'chosen'}; 
  182.         &editAccount; 
  183.     }
  184.     elsif ($fld{'doedit'}) { &formValid_doEdit; &doEdit; &getAccounts; &generic; }
  185.     elsif ($fld{'doit'}) { &tryToDelete; &getAccounts; &generic; }
  186.     elsif ($fld{'doadd'}) { &formValid_doAdd; &doAdd; &getAccounts; &generic; }
  187.     else { $message = "Use buttons to submit form."; $val{'new_account'} = $fld{'new_account'}; &generic; }
  188. } else { &generic; }
  189.  
  190. sub formValid_doAdd {
  191.     if (!$fld{'password'}) 
  192.     { &error(0,"You must enter a password."); }
  193.     if ($fld{'password'} ne $fld{'passcheck'}) 
  194.     { &error(0,"Input passwords not equivalent."); }
  195.     &error(0,"Invalid login name.") if $fld{'login'} =~ /$METACHARS/o;
  196. }
  197.  
  198. sub formValid_doEdit {
  199.     if ($fld{'password'} ne $fld{'passcheck'}) 
  200.     { &error(1,"Input passwords not equivalent."); }
  201.     &error(1,"Invalid login name.") if $fld{'login'} =~ /$METACHARS/o;
  202. }
  203.  
  204. sub error {
  205.     &error_block($_[1]);
  206.     %val = %fld;
  207.     if ($_[0] == 0) { &addAccount; }
  208.     elsif ($_[0] == 1) { &editAccount; }
  209.     else { &generic; }
  210.     exit 0;
  211. }
  212.  
  213. sub doEdit {
  214.    open(IN,"< $conf");
  215.     open(OUT,"> $dummy");
  216.     while(<IN>) {
  217.     @items = split(/:/);
  218.     if ($items[0] ne $fld{'chosen'}) { print OUT $_; }
  219.     else { $oldcrypt = $items[1]; }
  220.     }
  221.     close(IN);
  222.     close(OUT);
  223.     rename($dummy,$conf);
  224.  
  225.     if ($fld{'password'}) {
  226.     &add_password($fld{'login'},$fld{'password'},0,0,$fld{'login'}." ppp","/","/usr/etc/ppp");
  227.     } else {
  228.     open(OUT,">> $conf");
  229.     print OUT "$fld{'login'}:$oldcrypt:0:0:$fld{'login'} ppp:/:/usr/etc/ppp\n";
  230.     close(OUT);
  231.     }
  232.     
  233.     $message = "Account edited.";
  234. }    
  235.  
  236. sub editAccount {
  237.     &js_title_block($title,$js_edit);
  238.     &header_block("Edit Dial-in PPP Account");
  239.  
  240.     print "<form name=EditForm action=$myname method=post onSubmit=\"return runSubmit()\">";
  241.  
  242.     print qq|<input type=hidden name="chosen" value=$fld{'chosen'}>|;
  243.  
  244.     print "<center><table cellpadding=5 width=450>";
  245.  
  246.     print "<tr><th align=left>Login name:</th><th align=left>",
  247.       &text('login',$val{'login'}, 20),"</th></tr>";
  248.  
  249.     print "<tr><th align=left>Password:</th><th align=left>";
  250.     print qq|<input type=password name="password" size=20>|;
  251.     print "</th></tr>";
  252.     print "<tr><th align=left>(Password again):</th><th align=left>";
  253.     print qq|<input type=password name="passcheck" size=20>|;
  254.     print "</th></tr>";
  255.  
  256.     print "</table></center>";
  257.  
  258.     print &js_buttons('doedit','Ok','onClick="markOK()"','onClick="markOther()"');
  259.  
  260.     print "</form></body></html>";
  261. }
  262.     
  263. sub tryToDelete {
  264.     $account = $fld{'del_name'};
  265.     if ($account eq "") { return; }
  266.  
  267.     open(IN,"< $conf");
  268.     open(OUT,"> $dummy");
  269.     while(<IN>) {
  270.     $line = $_;
  271.     if ($line =~ /^\s*\#/) { print OUT $line; next; }
  272.     @items = split(/:/,$line);
  273.     chop $items[6];
  274.     if ($items[6] eq "/usr/etc/ppp" && $items[0] eq $account) {
  275.         next;
  276.     } else { print OUT $line; }
  277.     }
  278.     close(IN);
  279.     close(OUT);
  280.     rename($dummy,$conf);
  281.  
  282.     $message = "Account deleted.";    
  283. }
  284.  
  285. sub doAdd {
  286.     &add_password($fld{'login'},$fld{'password'},0,0,$fld{'login'}." ppp",
  287.         "/","/usr/etc/ppp");
  288.     $message = "New account added.";
  289. }
  290.  
  291. sub addAccount {
  292.     &js_title_block($title,$js_add);
  293.     &header_block("Add New Dial-in PPP Account");
  294.  
  295.     print "<form name=AddForm action=$myname method=post onSubmit=\"return runSubmit()\">";
  296.  
  297.     print "<center><table>";
  298.  
  299.     print "<input type=hidden name=login value=$val{'login'}>";
  300.  
  301.     print "<tr><th align=left>Login name:</th><td><tt>",
  302.       $val{'login'},"</tt></td></tr>";
  303.  
  304.     print "<tr><th align=left>Password:</th><th align=left>";
  305.     print qq|<input type=password name="password" size=20>|;
  306.     print "</th></tr>";
  307.  
  308.     print "<tr><th align=left>(Password again):</th><th align=left>";
  309.     print qq|<input type=password name="passcheck" size=20>|;
  310.     print "</th></tr>";
  311.  
  312.     print "</table></center><br>";
  313.  
  314.     print &js_buttons('doadd','Ok','onClick="markOK()"','onClick="markOther()"');
  315.  
  316.     print "</form></body></html>";
  317. }
  318.  
  319. sub getAccounts {
  320.     $i = 0;
  321.     open(IN,"< $conf");
  322.     while(<IN>) {
  323.     $line = $_;
  324.     if ($line =~ /^\s*\#/) { next; }
  325.     @items = split(/:/,$line);
  326.     chop $items[6];
  327.     if ($items[6] eq "/usr/etc/ppp") {
  328.         $name[$i] = $items[0];
  329.         $i++;
  330.     }
  331.     }
  332.     $number = $i;
  333.     close(IN);
  334. }
  335.  
  336. sub generic {
  337.     &js_title_block($title,$js_main);
  338.     &header_block($title);
  339.  
  340.     if (!$number && !$message) { $message = "No existing dial-in PPP accounts."; }
  341.     print "<i>$message</i>";
  342.  
  343.     print "<form name=PPPForm action=$myname method=post onSubmit=\"return runSubmit()\">";
  344.     
  345.     if ($_[0]) { print qq|<input type=hidden name="del_name" value=$_[0]>|; }
  346.  
  347.     if ($number) {
  348.     print "<h3>Account name:</h3><center>";
  349.  
  350.     print "<table width=400>";
  351.  
  352.     print qq|<tr><td><input type=submit name="add" value="Add New Account"
  353. onClick="markAdd()">
  354.         </td><td><input name="new_account" value="$val{'new_account'}" size=19></td></tr>|;
  355.  
  356.     print "<tr><td>";
  357.     print qq|<input type=submit name="edit" 
  358.         value="Edit Selected Account" onClick="markEdit()"></td>|;
  359.  
  360.     undef @locList;
  361.     for ($i=0;$i<$number;$i++) { 
  362.         if ($_[0] ne $name[$i]) { push(@locList,$name[$i]); }
  363.     }
  364.  
  365.     print "<td rowspan=2>";
  366.  
  367.     print &choice_list(*locList,"chosen",20);
  368.  
  369.     print "</td></tr>";
  370.  
  371.     print qq|<tr><td><input type=submit name="delete" 
  372.         value="Delete Selected Account" onClick="markDelete()"></td></tr>|;    
  373.  
  374.  
  375.     print "</table></center><br>";
  376.     } else {
  377.     print "<center><table width=400>";
  378.  
  379.     print qq|<tr><td><input type=submit name="add" value="Add New Account"
  380. onClick="markAdd()">
  381.         </td><td><input name="new_account" value="$val{'new_account'}" size=19></td></tr>|;
  382.  
  383.     print "<tr><td>";
  384.     print "</table>";
  385.     }
  386.  
  387.     print &js_buttons('doit','Ok','onClick="markOther()"','onClick="markOther()"');
  388.  
  389.     print "</form></body></html>";
  390. }
  391.  
  392.